package com.itheima.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.itheima.domain.City;
import com.itheima.domain.Pro;
import com.itheima.service.CityService;
import com.itheima.service.ProService;
import com.itheima.service.impl.CityServiceImpl;
import com.itheima.service.impl.ProServiceImpl;

import java.io.IOException;
import java.util.List;

@WebServlet("/cityServlet")
public class CityServlet extends HttpSevlet {
    private CityService service=new CityServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pid = req.getParameter("pid");
        List<City> list= service.findByPid(Integer.parseInt(pid));
        //转换json格式字符串
        ObjectMapper obj=new ObjectMapper();
        String json = obj.writeValueAsString(list);

        resp.setContentType("text/json;charset=utf-8");
        resp.getWriter().write(json);
    }
}
